﻿@using Permissions
@using Abp.Web.Mvc.Extensions
@model Abp.Application.Services.Dto.ListResultDto<Permissions.RoleApp.Dto.RoleDto>

@{
    ViewBag.Title = "Employee";
}

<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
    $(function () {
        var Id = decodeURI(window.location.href.split("/Employee_Role/Index/")[1]);
        $.ajax({
            type: "get",
            data: { "Id": Id },
            url: "/Employee_Role/Employee_Role",
            success: function (data) {
                var data = JSON.parse(data).data;

                var str = new Array();
                $('input[name="choice"]').each(function () {
                    str.push($(this).val());
                }); 

                for (var o in data) {
                    for (var i in str) {
                        if (str[i] == data[o].Id) {
                            console.log(data[o].Id)
                            $("input[name='choice'][value=" + data[o].Id+"]").attr("checked", true);
                        }
                    }
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //alert("Building error:" + errorThrown);
            }
        })

        $("#btnAdd").click(function () {
            var obj = document.getElementsByName("choice");
            var check_val = [];
            var check_text = [];
            for (var o in obj) {
                if (obj[o].checked) {
                    check_val.push(obj[o].value);
                    check_text.push(obj[o].nextSibling.nodeValue);
                }
            }
            //alert(check_text)
            $.ajax({
                type: "post",
                data: { "check_val": check_val, "check_text": check_text },
                url: "/Employee_Role/AddEmployee_Role",
                dataType: "string",
                success: function (data) {
                    alert(data)
                    if (true) {

                    } else {

                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert("Building error:" + errorThrown);
                }
            })
        })

        $("#CheckedAll").click(function () {
            if (this.checked) {
                $("[name=choice]").attr("checked", true);
            }
            else { $("[name=choice]").attr("checked", false); }
        })
    })
</script>

<div>
    <input type="checkbox" id="CheckedAll" />全选
    <br />
    <br />
    @foreach (var role in Model.Items)
    {
        <input type="checkbox" name="choice" class="checknum" value="@role.Id" />@role.Name
    }

    <button class="btn btn-primary pull-right" id="btnAdd">
        <i class="fa fa-plus"></i> 权限设置
    </button>
</div>

